import Foundation
import UIKit
import SnapKit


class UserInfoBlockStack: UIStackView {
    private var blockName: UILabel
    private var smallInfoBlockStack: UIStackView
    
    override init(frame: CGRect) {
        self.blockName = UILabel()
        
        self.smallInfoBlockStack = UIStackView()
        super.init(frame: frame)
        attributeInit()
        setupUI()
    }
    
    required init(coder: NSCoder) {
        fatalError("init(coder:NSCoder) -- fatalError")
    }
    func setBlockName(name:String){
        self.blockName.text = name
        self.blockName.adjustsFontSizeToFitWidth = true
        self.blockName.font = UIFont.systemFont(ofSize: 20,weight: .bold)
    }
    //属性设置
    func attributeInit(){
        self.axis = .vertical
        self.alignment = .fill
        self.distribution = .fill
    }
    func setupUI() {
        //下方stack
        smallInfoBlockStack.axis = .horizontal
        smallInfoBlockStack.alignment = .fill
        smallInfoBlockStack.distribution = .fill
        smallInfoBlockStack.spacing = 32
        
        //组装
        self.addArrangedSubview(blockName)
        self.addArrangedSubview(smallInfoBlockStack)
        
        //组件布局
        blockName.snp.makeConstraints({make in
            make.top.equalTo(0)
            make.left.equalToSuperview().inset(15)
            make.width.equalTo(118)
            make.height.equalTo(40)
        })//y=20
        smallInfoBlockStack.snp.makeConstraints({make in
            make.top.equalTo(blockName.snp.bottom).inset(5)
        })
    }
    func configure(numberlable:String,lablename:String){
        //设置stack
        let stack = UIStackView()
        stack.axis = .vertical
        stack.alignment = .fill
        stack.distribution = .fill
        
        //设置显示的内容
        let numL = UILabel()
        let labL = UILabel()
        numL.text = numberlable
        labL.text = lablename
        numL.font = UIFont.systemFont(ofSize: 20,weight: .bold)
        labL.font = UIFont.systemFont(ofSize: 12,weight: .light)
        labL.textColor = .black
        //组装
        stack.addArrangedSubview(numL)
        stack.addArrangedSubview(labL)
        smallInfoBlockStack.addArrangedSubview(stack)
        
        //组件布局
        numL.snp.makeConstraints({make in
            make.top.equalTo(0)
            make.width.equalTo(21)
            make.height.equalTo(17)
        })
        labL.snp.makeConstraints({make in
            make.top.equalToSuperview().inset(21)
            make.width.equalTo(48)
            make.height.equalTo(17)
        })
        stack.snp.makeConstraints { make in
            make.width.equalTo(48)
            make.height.equalTo(38)
        }
        
    }
}
